<?php
/**
 * 在rewrite 模式下Index模块的其他方法可能会转入空操作，这是PATH_INFO参数缺陷。
 * 修复办法：
 * 1、在空操作中做单独处理
 * 2、dispaly强制指定模板
 * @author Administrator
 *
 */
class IndexAction extends CommonAction{
    //首页    
	public function index(){
//		dump(ch1('class','0','13','class0:60'));exit;		
		$this->seo();
		$this->display();
    }
	//站长日记
	public function diary(){
		$this->seo('站长日记');
		$this->display('Index:diary');
	}
	
	//站内搜索，可修改定制
	public function search(){
		header('Content-Type:text/html;charset=utf-8');
		$keytype = ucfirst(strtolower(htmlspecialchars(trim($_REQUEST['keytype']))));
		$keyword = htmlspecialchars(trim($_REQUEST['keyword']));
		//$keyword = iconv('gbk', 'utf-8', $keyword);
		if($keytype!=''){			
			import("Db");
			$db =   DB::getInstance();  
			$tables = $db->getTables();
			$keytype = (in_array(C('DB_PREFIX').strtolower($keytype), $tables)) ? $keytype : 'Article';			
		}else{
			$keytype = 'Article';
		}
		
		$fields = M($keytype)->getDbFields();
		$checkField = array();
		if(in_array('title',$fields)) $checkField['title'] = 'keyword';
		if(in_array('content',$fields)) $checkField['content'] = 'keyword';
		
		$where = getSearchMap($checkField);
		if($where){ 
			$where['_logic'] = 'OR';
			$map['_complex'] = $where;
		}	
		parent::$map = $map;
		
		parent::$pos = '在'.M('Model')->where(array('ename'=>$keytype))->getField('cname').'中搜索'.$keyword.'的结果';
		
		$this->seo(parent::$pos);
		$this->assign('keytype',$keytype);
		$this->assign('keyword',$keyword);	
		$this->display('Index:search');
	}
}